package com.anolesoft.integration.controller;

import com.anolesoft.common.security.service.SysLoginService;
import com.anolesoft.integration.service.LoginForOthersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zyq
 * @date 2022/12/9
 */
@RestController
@CrossOrigin
@RequestMapping("/integration")
@Slf4j
public class LoginForOthersController {

    @Autowired
    private LoginForOthersService loginForOthersService;
    @Autowired
    private SysLoginService sysLoginService;

    @PostMapping(value = "/login",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String loginInfo(@RequestBody Map<String,String> map) throws Exception{
        String eid = map.get("eid");
        String factoryId = map.get("factoryId");
        Map<String,String> loginUser = this.loginForOthersService.loginInfo(eid,factoryId);
        log.debug("result:{}",loginUser);
        String userName = loginUser.get("USERNAME");
        String password = loginUser.get("PASSWORD");
        System.out.println(userName + "and" + password);
        String code = "3";
        String uuid = "4";
        String token = sysLoginService.login(userName,password,code,uuid);
        return token;
    }
}
